<template>
  <div>
    <h1>请充会员卡</h1>
    <h1>{{sum}}</h1>
  </div>
</template>

<script>
export default {
  data() {
    return {
      sum: 0
    };
  },
  beforeRouteEnter(to, from, next) {
    next(component => {
      console.log(component.sum);
      component.intervalNum = setInterval(() => {
        component.sum += 648;
      }, 1000);
    });
  },
  // 离开组件之前，做一些收尾工作
  beforeRouteLeave(to, from, next) {
    clearInterval(this.intervalNum);
    console.log(this.sum);
    next();
  }
};
</script>

<style>
</style>